/*
 * @Author: scl
 * @Date: 2023-09-19 14:17:30
 * @LastEditTime: 2023-09-20 00:26:10
 * @Description: file content
 */
import type { orderCreateParams, orderListParams, orderListResult, orderLogisticResult, orderPreResult, orderResult } from '@/types/order'
import { http } from '@/utils/http'

/**填写订单-获取预付订单 */
export const getMemberOrderPreAPI = () => {
    return http<orderPreResult>({
        url: "/member/order/pre",
        method: "GET"
    })
}
/**
 * 填写订单-获取立即购买订单
 */
export const getMemberOrderPreNowAPI = (data: {
    skuId: string
    count: string
    addressId?: string
}) => {
    return http<orderPreResult>({
        method: 'GET',
        url: '/member/order/pre/now',
        data,
    })
}
/**
 * 提交订单
 * @param data 请求参数
 */
export const postMemberOrderAPI = (data: orderCreateParams) => {
    return http<{ id: string }>({
        method: 'POST',
        url: '/member/order',
        data,
    })
}/**
 * 获取订单详情
 * @param id 订单id
 */
export const getMemberOrderByIdAPI = (id: string) => {
    return http<orderResult>({
        method: 'GET',
        url: `/member/order/${id}`,
    })
}
/**
 * 填写订单-再次购买
 * @param id 订单id
 */
export const getMemberOrderRepurchaseByIdAPI = (id: string) => {
    return http<orderPreResult>({
        method: 'GET',
        url: `/member/order/repurchase/${id}`,
    })
}
/**
 * 模拟发货-内测版
 * @description 在DEV环境下使用，仅在订单状态为待发货时，可模拟发货，调用后订单状态修改为待收货，包含模拟物流。
 * @param id 订单id
 */
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
    return http({
        method: 'GET',
        url: `/member/order/consignment/${id}`,
    })
}
/**
 * 确认收货
 * @description 仅在订单状态为待收货时，可确认收货。
 * @param id 订单id
 */
export const putMemberOrderReceiptByIdAPI = (id: string) => {
    return http<orderResult>({
        method: 'PUT',
        url: `/member/order/${id}/receipt`,
    })
}
/**
 * 获取订单物流
 * @description 仅在订单状态为待收货，待评价，已完成时，可获取物流信息。
 * @param id 订单id
 */
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
    return http<orderLogisticResult>({
        method: 'GET',
        url: `/member/order/${id}/logistics`,
    })
}
/**
 * 删除订单
 * @description 仅在订单状态为待评价，已完成，已取消时，可删除订单。
 * @param data ids 订单集合
 */
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
    return http({
        method: 'DELETE',
        url: `/member/order`,
        data,
    })
}
/**
 * 取消订单
 * @description 仅在订单状态为待付款时，可取消订单。
 * @param id 订单id
 * @param data cancelReason 取消理由
 */
export const getMemberOrderCancelByIdAPI = (
    id: string,
    data: { cancelReason: string },
) => {
    return http<orderResult>({
        method: 'PUT',
        url: `/member/order/${id}/cancel`,
        data,
    })
}
/**
 * 获取订单列表
 * @param data orderState 订单状态
 */
export const getMemberOrderAPI = (data: orderListParams) => {
    return http<orderListResult>({
        method: 'GET',
        url: `/member/order`,
        data,
    })
}